/**
 * login.js-
 */
import request from '../request'
class login {
  constructor() {
    this._defaultHeader = {
      'data-tupe': 'application/json'
    }
    this._request = new request
    this._request.setErrorHandler(this.errorHander)
  }

  /**
   * 统一的异常处理方法
   */
  errorHander(res) {
    console.error(res)
  }


  /**
   * w微信授权登录
   */
  loginByWechat(data) {
    const app = getApp()
    return this._request.getRequest(app.globalData._baseUrl + 'home/login-by-wechat', data).then(res => res.data)
  }

  /**
   * 获取code
   */
  getCode(data) {
    const app = getApp()
    return this._request.getRequest(app.globalData._baseUrl + 'home/get-code', data).then(res => res.data)
  }

  /**
   * 通过code登录
   */
  loginByCode(data) {
    const app = getApp()
    return this._request.getRequest(app.globalData._baseUrl + 'home/login-by-code', data).then(res => res.data)
  }

  /**
   * 获取sessionKey
   */
  getSessionKey(data) {
    const app = getApp()
    return this._request.getRequest(app.globalData.wxUrl + 'sns/jscode2session', data).then(res => res.data)
  }

}
export default login